﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TravelLink.WebModel;

namespace TravelLink.WebApp.UserControl {
    public partial class UC_Index : ControlBase {
        protected void Page_Load(object sender, EventArgs e) {
            if (this.Page.Master is HighMainFrm) {
                (this.Page.Master as HighMainFrm).SetNavDisplay(false);
            }

            this.drpPositionLv.DataSource = this.DB.TL_PositionLevel;
            this.drpPositionLv.DataTextField = "Name";
            this.drpPositionLv.DataValueField = "Idx";
            this.drpPositionLv.DataBind();
            this.drpPositionLv.Items.Insert(0, new ListItem("--不限--", "-1"));


            this.drpPositionJobType.DataSource = this.DB.TL_PositionType;
            this.drpPositionJobType.DataTextField = "Name";
            this.drpPositionJobType.DataValueField = "Idx";
            this.drpPositionJobType.DataBind();
            this.drpPositionJobType.Items.Insert(0, new ListItem("--不限--", "-1"));


            var imageSource = this.DB.TL_HotPosition.Where(u => u.Image != null && u.Image != string.Empty).Select(u => new IndexScrollImage {
                ImagePath = string.Concat("/Images/HtmlInfo/", u.Image),
                Link = string.Concat("/CompanyPosition.aspx?ist=&pl=-1&pt=-1&dt=0&ct=&ctn=&cpy=" + DB.TL_Company_Position.Where(t => t.PositionCode == u.PositionCode).Select(t => t.CompanyCode).FirstOrDefault()),
                Order = u.SortId ?? 0
            }).OrderBy(u => u.Order);
            if (imageSource.Count() > 0) {
                rptImageDataSource.DataSource = imageSource;
                rptImageDataSource.DataBind();
                this.labEmptyImage.Visible = false;
                this.rptImageDataSource.Visible = true;
            }
            else {
                this.labEmptyImage.Visible = true;
                rptImageDataSource.Visible = false;
            }
        }
    }



    public class IndexScrollImage {
        public string ImagePath { get; set; }

        public string Link { get; set; }

        public int Order { get; set; }
    }
}